import { ref } from "vue"
import { getActiveLangName, setActiveLangName } from "@/utils/cache/localStorage"



const DEFAULT_LANG_NAME = "zh" 
type DefaultLangNameType = typeof DEFAULT_LANG_NAME

export type LangName = DefaultLangNameType | 'en' | "ja"

interface ILangList {
    title: string
    name: LangName
  }

/** 语言列表 */
const langList: ILangList[] = [
    { title: '简体-中文', name: 'zh' },
    { title: 'English', name: 'en' },
    { title: '日本語', name: 'ja' }
]
/** 正在使用的语言 */
const ActiveLangName = ref<LangName>(getActiveLangName() || DEFAULT_LANG_NAME) 

/** 设置语言 */
const setLang = (langName:LangName)=>{
    ActiveLangName.value = langName
    
    setActiveLangName(langName)
} 
/** 主题 hook */
export function useLang() {
    return { langList, ActiveLangName, setLang }
  }